package cn.supermaster.management.web.service.system.impl;

import cn.supermaster.management.common.domain.SystemUser;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.common.utils.WebHelper;
import cn.supermaster.management.core.component.RegisterManager;
import cn.supermaster.management.system.service.ISystemConfigurationService;
import cn.supermaster.management.web.service.system.ISRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.service.system.impl
 * @ClassName: SRegisterServiceImpl
 * @Description: []
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/12 1:05
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Service
public class SRegisterServiceImpl implements ISRegisterService {

    @Autowired
    private RegisterManager registerManager;

    @Autowired
    private ISystemConfigurationService configService;

    /**
     * @Description: [跳转注册界面]
     * <p></P>
     * @Title: skipRegisterHtml
     * @Author: Lance Ting
     * @Date: 2021-01-12
     * @Return: java.lang.String
     */
    @Override
    public String skipRegisterHtml() {
        return "register";
    }

    /**
     * @Description: [用户注册]
     * <p></P>
     * @Title: doUserRegister
     * @Author: Lance Ting
     * @Date: 2021-01-12
     * @Param: user
     * @Return: cn.supermaster.management.common.response.WebResult
     */
    @Override
    public WebResponse doUserRegister(SystemUser user) {
        if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) {
            return WebHelper.error("当前系统没有开启注册功能！");
        }
        String msg = registerManager.doAccountRegister(user);
        return StringUtils.isEmpty(msg) ? WebHelper.success() : WebHelper.error(msg);
    }
}